package com.itheima.homework.bh2003;

/*
【编号2003】某电影院目前正在上映国产大片，共有100张票，而它有3个窗口卖票，
请设计一个程序模拟该电影院卖票，并保证线程同步，不会出现错误的买票数据。
 */
public class Test3 {
    public static void main(String[] args) {
        MyThread mp1 = new MyThread();
        MyThread mp2 = new MyThread();
        MyThread mp3 = new MyThread();
        mp1.setName("窗口一");
        mp2.setName("窗口二");
        mp3.setName("窗口三");
        mp1.start();
        mp2.start();
        mp3.start();
    }
}
class MyThread extends Thread {
    private static int tickCount = 100;
    @Override
    public void run() {
        while (true) {
            synchronized ("a") {
                if (tickCount <= 0) {
                    break;
                } else {
                    try {
                        Thread.sleep(200);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    tickCount--;
                    System.out.println(Thread.currentThread().getName() + "在卖票，还剩下" + tickCount + "张票");
                }
            }
        }
    }
}